package be.kuleuven.peno3.mobiletoledo.Data.Client;


import java.io.IOException;
import com.google.gson.Gson;

import be.kuleuven.peno3.mobiletoledo.model.Announcement;

public class AnnouncementClient extends Client {
	public  static Announcement[] getAnnouncements(int course_id){
		try {
			String url ="course_id="+ course_id +"";
			url=host+"/AnnouncementHandler/getAnnouncements?"+url;
			url=encode(url);
			String json = stringOfUrl(url);
			System.out.println(url);
			Announcement[] announcements =new Gson().fromJson(json.toString(), Announcement[].class);
			return announcements;
			
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
			return null;
		}
		catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}
	public static Announcement getAnnouncement(int announcement_id){
		try {
			String url ="announcement_id="+ announcement_id +"";
			url=host+"/AnnouncementHandler/getAnnouncement?"+url;
			url=encode(url);
			String json = stringOfUrl(url);
			System.out.println(url);
			Announcement[] announcements =new Gson().fromJson(json.toString(), Announcement[].class);
			if (announcements !=null){
				return announcements[0];
			}
			else {
				return null;
			}
		}
		catch (IOException e) {
			e.printStackTrace();
			return null;
		}
		
		
	}
}
